引用下拉框下拉框

2023-09-10 15:00:01 作者:指尖、花凉忆成殇

我有这个code来验证。

 <脚本类型=文/ JavaScript的> <! - 警报(测试); - > < / SCRIPT>
 

这code使得现在的表单页面弹出框。所有工作如预期!现在我遇到的问题是引用下拉框。我想下面的code应该做的伎俩,但没有。

  VAR元素;变种I = EG;
元=的document.getElementById(client_country); element.selectedIndex =我;
 

不过,我似乎无法得到它的工作。我认为它是由于使用框架,任何人都可以点我,我要去哪里错了方向?

解决方案

  VAR I ='如'; //字符串引号内
VAR元=的document.getElementById(client_country);
element.value =我; //设置选择的选项

//的selectedIndex检索值
VAR selected_value = element.options [element.selectedIndex] .value的;
 
Excel使用技巧之设置单元格为下拉框

这里假设你有HTML类似...

 <选择ID =client_country>
    <期权价值=AG>价值< /选项>
    <期权价值=CG>价值℃下/选项>
    <期权价值=EG>价值e控制/选项>
< /选择>
 

拆装的jsfiddle 。

演示

I have this code to verify that.

<script type="text/javascript"> <!-- alert("Testing"); --> </script>

This code now makes a popup box on form page. All working as expected! Now the problem I'm having is referencing the drop-down box. I thought the following code should have done the trick but no.

var element; var i=EG;
element=document.getElementById("client_country"); element.selectedIndex = i;

But I cant seem to get it to work. I think its due to the use of frames, anyone able to point me in the direction of where I’m going wrong?

解决方案

var i = 'EG'; // string inside quotes
var element = document.getElementById("client_country");
element.value = i; // set the selected option

// selectedIndex retrieves the value
var selected_value = element.options[element.selectedIndex].value;

This assumes you have HTML similar to...

<select id="client_country">
    <option value="AG">value a</option>
    <option value="CG">value c</option>
    <option value="EG">value e</option>
</select>

Working demo on JSFiddle.

 
精彩推荐