如何使用 jquery 更改标签的文本,使其与从选择框中选择的值相同?

发布于 2024-12-11 20:47:05 字数 13824 浏览 0 评论 0原文

我有一个标签:

<label class="plan_code" id="plan_code-value">010</label>

当使用 Jquery 选择选项时,我试图更改其默认文本,

<select id="plan_code">
                                        <option value="010" class="odd">010</option>
                                        <option value="020" class="even">020</option>
                                        <option value="030" class="odd">030</option>
                                        <option value="040" class="even">040</option>
                                        <option value="041" class="odd">041</option>
                                        <option value="050" class="even">050</option>
                                        <option value="060" class="odd">060</option>
                                        <option value="070" class="even">070</option>
                                        <option value="080" class="odd">080</option>
                                        <option value="081" class="even">081</option>
                                        <option value="082" class="odd">082</option>
                                        <option value="090" class="even">090</option>
                                        <option value="100" class="odd">100</option>
                                        <option value="110" class="even">110</option>
                                        <option value="121" class="odd">121</option>
                                        <option value="130" class="even">130</option>
                                        <option value="140" class="odd">140</option>
                                        <option value="141" class="even">141</option>
                                        <option value="150" class="odd">150</option>
                                        <option value="160" class="even">160</option>
                                        <option value="170" class="odd">170</option>
                                        <option value="180" class="even">180</option>
                                        <option value="190" class="odd">190</option>
                                        <option value="200" class="even">200</option>
                                        <option value="210" class="odd">210</option>
                                        <option value="220" class="even">220</option>
                                        <option value="230" class="odd">230</option>
                                        <option value="240" class="even">240</option>
                                        <option value="241" class="odd">241</option>
                                        <option value="250" class="even">250</option>
                                        <option value="260" class="odd">260</option>
                                        <option value="265" class="even">265</option>
                                        <option value="270" class="odd">270</option>
                                        <option value="280" class="even">280</option>
                                        <option value="290" class="odd">290</option>
                                        <option value="301" class="even">301</option>
                                        <option value="303" class="odd">303</option>
                                        <option value="304" class="even">304</option>
                                        <option value="305" class="odd">305</option>
                                        <option value="306" class="even">306</option>
                                        <option value="310" class="odd">310</option>
                                        <option value="320" class="even">320</option>
                                        <option value="332" class="odd">332</option>
                                        <option value="333" class="even">333</option>
                                        <option value="339" class="odd">339</option>
                                        <option value="340" class="even">340</option>
                                        <option value="350" class="odd">350</option>
                                        <option value="361" class="even">361</option>
                                        <option value="362" class="odd">362</option>
                                        <option value="363" class="even">363</option>
                                        <option value="364" class="odd">364</option>
                                        <option value="370" class="even">370</option>
                                        <option value="380" class="odd">380</option>
                                        <option value="389" class="even">389</option>
                                        <option value="390" class="odd">390</option>
                                        <option value="392" class="even">392</option>
                                        <option value="400" class="odd">400</option>
                                        <option value="405" class="even">405</option>
                                        <option value="410" class="odd">410</option>
                                        <option value="415" class="even">415</option>
                                        <option value="432" class="odd">432</option>
                                        <option value="430" class="even">430</option>
                                        <option value="439" class="odd">439</option>
                                        <option value="441" class="even">441</option>
                                        <option value="443" class="odd">443</option>
                                        <option value="450" class="even">450</option>
                                        <option value="460" class="odd">460</option>
                                        <option value="470" class="even">470</option>
                                        <option value="471" class="odd">471</option>
                                        <option value="510" class="even">510</option>
                                        <option value="520" class="odd">520</option>
                                        <option value="530" class="even">530</option>
                                        <option value="542" class="odd">542</option>
                                        <option value="550" class="even">550</option>
                                        <option value="560" class="odd">560</option>
                                        <option value="570" class="even">570</option>
                                        <option value="580" class="odd">580</option>
                                        <option value="582" class="even">582</option>
                                        <option value="590" class="odd">590</option>
                                        <option value="600" class="even">600</option>
                                        <option value="610" class="odd">610</option>
                                        <option value="611" class="even">611</option>
                                        <option value="621" class="odd">621</option>
                                        <option value="630" class="even">630</option>
                                        <option value="640" class="odd">640</option>
                                        <option value="650" class="even">650</option>
                                        <option value="660" class="odd">660</option>
                                        <option value="670" class="even">670</option>
                                        <option value="680" class="odd">680</option>
                                        <option value="690" class="even">690</option>
                                        <option value="700" class="odd">700</option>
                                        <option value="710" class="even">710</option>
                                        <option value="720" class="odd">720</option>
                                        <option value="730" class="even">730</option>
                                        <option value="740" class="odd">740</option>
                                        <option value="741" class="even">741</option>
                                        <option value="751" class="odd">751</option>
                                        <option value="760" class="even">760</option>
                                        <option value="765" class="odd">765</option>
                                        <option value="770" class="even">770</option>
                                        <option value="777" class="odd">777</option>
                                        <option value="780" class="even">780</option>
                                        <option value="790" class="odd">790</option>
                                        <option value="800" class="even">800</option>
                                        <option value="801" class="odd">801</option>
                                        <option value="803" class="even">803</option>
                                        <option value="804" class="odd">804</option>
                                        <option value="805" class="even">805</option>
                                        <option value="806" class="odd">806</option>
                                        <option value="808" class="even">808</option>
                                        <option value="810" class="odd">810</option>
                                        <option value="820" class="even">820</option>
                                        <option value="833" class="odd">833</option>
                                        <option value="834" class="even">834</option>
                                        <option value="840" class="odd">840</option>
                                        <option value="851" class="even">851</option>
                                        <option value="856" class="odd">856</option>
                                        <option value="870" class="even">870</option>
                                        <option value="88" class="odd">88</option>
                                        <option value="889" class="even">889</option>
                                        <option value="890" class="odd">890</option>
                                        <option value="892" class="even">892</option>
                                        <option value="900" class="odd">900</option>
                                        <option value="905" class="even">905</option>
                                        <option value="910" class="odd">910</option>
                                        <option value="915" class="even">915</option>
                                        <option value="923" class="odd">923</option>
                                        <option value="932" class="even">932</option>
                                        <option value="934" class="odd">934</option>
                                        <option value="936" class="even">936</option>
                                        <option value="937" class="odd">937</option>
                                        <option value="939" class="even">939</option>
                                        <option value="941" class="odd">941</option>
                                        <option value="943" class="even">943</option>
                                        <option value="950" class="odd">950</option>
                                        <option value="960" class="even">960</option>
                                        <option value="970" class="odd">970</option>
                                        <option value="971" class="even">971</option>
                                        <option value="982" class="odd">982</option>
                                    </select>

我该如何完成此操作?

I have a label:

<label class="plan_code" id="plan_code-value">010</label>

I am trying to change its default text when an option is selected using Jquery

<select id="plan_code">
                                        <option value="010" class="odd">010</option>
                                        <option value="020" class="even">020</option>
                                        <option value="030" class="odd">030</option>
                                        <option value="040" class="even">040</option>
                                        <option value="041" class="odd">041</option>
                                        <option value="050" class="even">050</option>
                                        <option value="060" class="odd">060</option>
                                        <option value="070" class="even">070</option>
                                        <option value="080" class="odd">080</option>
                                        <option value="081" class="even">081</option>
                                        <option value="082" class="odd">082</option>
                                        <option value="090" class="even">090</option>
                                        <option value="100" class="odd">100</option>
                                        <option value="110" class="even">110</option>
                                        <option value="121" class="odd">121</option>
                                        <option value="130" class="even">130</option>
                                        <option value="140" class="odd">140</option>
                                        <option value="141" class="even">141</option>
                                        <option value="150" class="odd">150</option>
                                        <option value="160" class="even">160</option>
                                        <option value="170" class="odd">170</option>
                                        <option value="180" class="even">180</option>
                                        <option value="190" class="odd">190</option>
                                        <option value="200" class="even">200</option>
                                        <option value="210" class="odd">210</option>
                                        <option value="220" class="even">220</option>
                                        <option value="230" class="odd">230</option>
                                        <option value="240" class="even">240</option>
                                        <option value="241" class="odd">241</option>
                                        <option value="250" class="even">250</option>
                                        <option value="260" class="odd">260</option>
                                        <option value="265" class="even">265</option>
                                        <option value="270" class="odd">270</option>
                                        <option value="280" class="even">280</option>
                                        <option value="290" class="odd">290</option>
                                        <option value="301" class="even">301</option>
                                        <option value="303" class="odd">303</option>
                                        <option value="304" class="even">304</option>
                                        <option value="305" class="odd">305</option>
                                        <option value="306" class="even">306</option>
                                        <option value="310" class="odd">310</option>
                                        <option value="320" class="even">320</option>
                                        <option value="332" class="odd">332</option>
                                        <option value="333" class="even">333</option>
                                        <option value="339" class="odd">339</option>
                                        <option value="340" class="even">340</option>
                                        <option value="350" class="odd">350</option>
                                        <option value="361" class="even">361</option>
                                        <option value="362" class="odd">362</option>
                                        <option value="363" class="even">363</option>
                                        <option value="364" class="odd">364</option>
                                        <option value="370" class="even">370</option>
                                        <option value="380" class="odd">380</option>
                                        <option value="389" class="even">389</option>
                                        <option value="390" class="odd">390</option>
                                        <option value="392" class="even">392</option>
                                        <option value="400" class="odd">400</option>
                                        <option value="405" class="even">405</option>
                                        <option value="410" class="odd">410</option>
                                        <option value="415" class="even">415</option>
                                        <option value="432" class="odd">432</option>
                                        <option value="430" class="even">430</option>
                                        <option value="439" class="odd">439</option>
                                        <option value="441" class="even">441</option>
                                        <option value="443" class="odd">443</option>
                                        <option value="450" class="even">450</option>
                                        <option value="460" class="odd">460</option>
                                        <option value="470" class="even">470</option>
                                        <option value="471" class="odd">471</option>
                                        <option value="510" class="even">510</option>
                                        <option value="520" class="odd">520</option>
                                        <option value="530" class="even">530</option>
                                        <option value="542" class="odd">542</option>
                                        <option value="550" class="even">550</option>
                                        <option value="560" class="odd">560</option>
                                        <option value="570" class="even">570</option>
                                        <option value="580" class="odd">580</option>
                                        <option value="582" class="even">582</option>
                                        <option value="590" class="odd">590</option>
                                        <option value="600" class="even">600</option>
                                        <option value="610" class="odd">610</option>
                                        <option value="611" class="even">611</option>
                                        <option value="621" class="odd">621</option>
                                        <option value="630" class="even">630</option>
                                        <option value="640" class="odd">640</option>
                                        <option value="650" class="even">650</option>
                                        <option value="660" class="odd">660</option>
                                        <option value="670" class="even">670</option>
                                        <option value="680" class="odd">680</option>
                                        <option value="690" class="even">690</option>
                                        <option value="700" class="odd">700</option>
                                        <option value="710" class="even">710</option>
                                        <option value="720" class="odd">720</option>
                                        <option value="730" class="even">730</option>
                                        <option value="740" class="odd">740</option>
                                        <option value="741" class="even">741</option>
                                        <option value="751" class="odd">751</option>
                                        <option value="760" class="even">760</option>
                                        <option value="765" class="odd">765</option>
                                        <option value="770" class="even">770</option>
                                        <option value="777" class="odd">777</option>
                                        <option value="780" class="even">780</option>
                                        <option value="790" class="odd">790</option>
                                        <option value="800" class="even">800</option>
                                        <option value="801" class="odd">801</option>
                                        <option value="803" class="even">803</option>
                                        <option value="804" class="odd">804</option>
                                        <option value="805" class="even">805</option>
                                        <option value="806" class="odd">806</option>
                                        <option value="808" class="even">808</option>
                                        <option value="810" class="odd">810</option>
                                        <option value="820" class="even">820</option>
                                        <option value="833" class="odd">833</option>
                                        <option value="834" class="even">834</option>
                                        <option value="840" class="odd">840</option>
                                        <option value="851" class="even">851</option>
                                        <option value="856" class="odd">856</option>
                                        <option value="870" class="even">870</option>
                                        <option value="88" class="odd">88</option>
                                        <option value="889" class="even">889</option>
                                        <option value="890" class="odd">890</option>
                                        <option value="892" class="even">892</option>
                                        <option value="900" class="odd">900</option>
                                        <option value="905" class="even">905</option>
                                        <option value="910" class="odd">910</option>
                                        <option value="915" class="even">915</option>
                                        <option value="923" class="odd">923</option>
                                        <option value="932" class="even">932</option>
                                        <option value="934" class="odd">934</option>
                                        <option value="936" class="even">936</option>
                                        <option value="937" class="odd">937</option>
                                        <option value="939" class="even">939</option>
                                        <option value="941" class="odd">941</option>
                                        <option value="943" class="even">943</option>
                                        <option value="950" class="odd">950</option>
                                        <option value="960" class="even">960</option>
                                        <option value="970" class="odd">970</option>
                                        <option value="971" class="even">971</option>
                                        <option value="982" class="odd">982</option>
                                    </select>

how can I accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-12-18 20:47:05
$(document).ready(function() {
  $('#plan_code').change(function() {
    $('#plan_code-value').html($(this).val());
  });
});

编辑

我将代码包装在 $(document).ready() 中,以便在 DOM 准备好时执行

$(document).ready(function() {
  $('#plan_code').change(function() {
    $('#plan_code-value').html($(this).val());
  });
});

EDIT

I wrapped the code in $(document).ready() so it's executed when the DOM is ready

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文