猿问

我正在尝试根据条件进行 jQuery 删除

所以我想使用 jquery 删除整个 div 及其内容


运行 javascript 函数查找 IP 地址后,区域的值将输入到 jquery 这里是从 IP 地址中查找区域的 javascript


$(document).ready(function() {

            $.get("https://geo.ipify.org/api/v1?apiKey=", function(data) {


                $("body").append("<pre>" + JSON.stringify(data.location.region, "", 2) + "</pre>");


因此,如果 data.location.region 是 texas,那么我希望所有区域值不等于 texas 的 div class=msa 消失。


所以我需要一个 jquery 函数,我猜它需要该区域并执行 removeClass。


这是样本主体`


<div class="row m-s-a _hidden">

    <table>

        <tr>

            <td class="for-sale-heading">

                <h4>Auction:&nbsp;</h4>

            </td>

            <td class="for-sale-heading">

                <h4>Hard rock Cafe</h4>

            </td>

        </tr>

        <tr>

            <td class="for-sale-heading">

                <h4>Location:&nbsp;</h4>

            </td>

            <td class="for-sale-heading">

                <h4>4641 Production unit 42 Mt. Clemens, <span `enter code here`class="region">Michigan</span> 48043</h4>

            </td>

        </tr>

    </table>

</div>

<div class="row m-s-a _hidden">`enter code here`

    <table>

        <tr>

            <td class="for-sale-heading">

                <h4>Auction:&nbsp;</h4>

            </td>

            <td class="for-sale-heading">

                <h4>Hard rock Cafe</h4>

            </td>

        </tr>

        <tr>

            <td class="for-sale-heading">

                <h4>Location:&nbsp;</h4>

            </td>

            <td class="for-sale-heading">

                <h4>4641 Production unit 42 Mt. Clemens, <span class="region">Utah</span> 48043</h4>

            </td>

        </tr>

    </table>

</div>

<div class="row m-s-a _hidden">

    <table>

        <tr>

            <td class="for-sale-heading">

                <h4>Auction:&nbsp;</h4>

            </td>

            <td class="for-sale-heading">

                <h4>Hard rock Cafe</h4>

            </td>

        </tr>



守着一只汪
浏览 92回答 1
1回答

四季花海

你可以这样做:$(document).ready(function() {&nbsp; $(".region").each(function() {&nbsp; &nbsp; if ($(this).text() != "Texas") {&nbsp; &nbsp; &nbsp; $(this).closest(".m-s-a").remove();&nbsp; &nbsp; }&nbsp; });});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div class="row m-s-a _hidden">&nbsp; <table>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Auction:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Hard rock Cafe</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Location:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>4641 Production unit 42 Mt. Clemens, <span class="region">Michigan</span> 48043</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; </table></div><div class="row m-s-a _hidden">&nbsp; <table>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Auction:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Hard rock Cafe</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Location:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>4641 Production unit 42 Mt. Clemens, <span class="region">Utah</span> 48043</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; </table></div><div class="row m-s-a _hidden">&nbsp; <table>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Auction:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Hard rock Cafe</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>Location:&nbsp;</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; <td class="for-sale-heading">&nbsp; &nbsp; &nbsp; &nbsp; <h4>4641 Production unit 42 Mt. Clemens, <span class="region">Texas</span> 48043</h4>&nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; </table></div>这必须根据您的需要进行调整,例如,与其将 的文本与<span class="region">“Texas”进行比较,不如将其与data.location.region您<pre>在示例中添加此区域的位置进行比较 -&nbsp;$("pre").text(),以防它是<pre>您页面上唯一的。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答