Javascript 仅更改HTML选项标记中的数字

Javascript 仅更改HTML选项标记中的数字,javascript,jquery,Javascript,Jquery,如何使用JS更改选项标记中的数字 <select name="resunit"> <option value="res_0">R1 (18768194)</option> <option value="res_1">R2 (44507354)</option> <option value="res_2">R3 (15217874)</option> <option value

如何使用JS更改选项标记中的数字

<select name="resunit">
    <option value="res_0">R1 (18768194)</option>
    <option value="res_1">R2 (44507354)</option>
    <option value="res_2">R3 (15217874)</option>
    <option value="unit_1">U1 (3047)</option>
    <option value="unit_2">U2 (10)</option>
    <option value="unit_3">U3 (60)</option>
</select>

R1(18768194)
R2(44507354)
R3(15217874)
U1(3047)
U2(10)
U3(60)
e、 g

R1(18768194)

R1(10)

不太清楚你在问什么,但看看:

var select = document.getElementsByName("resunit")[0];

for (var i = 0; i < select.length; i++) {
    if (select[i].value === "res_0") {
        select[i].innerHTML = "R1 (10)";
    } else if (select[i].value === "res_1") {
        select[i].innerHTML = "R2 (12)";
    }
}
var select=document.getElementsByName(“resunit”)[0];
对于(变量i=0;i
您需要一个regex和replace函数,但我们需要更多关于条件的信息。是否只有R类型将被更改?R数字有多远?数字总是在括号中吗?只有括号中的数字还有其他问题吗?例如:
if($($select[name=resunit]option”).val()=“res_0”)
然后将()中的数字改为10或
如果($($select[name=resunit]option”).val()=“resu 1”)
然后将()至12代码是否还需要检查U选项?
<option value="res_0">R1 (10)</option>
var select = document.getElementsByName("resunit")[0];

for (var i = 0; i < select.length; i++) {
    if (select[i].value === "res_0") {
        select[i].innerHTML = "R1 (10)";
    } else if (select[i].value === "res_1") {
        select[i].innerHTML = "R2 (12)";
    }
}