将字符串变量分配给html <option value =“....”> tag </option>

时间:2012-12-15 12:38:08

标签: javascript html

我想传递一个动态变化的字符串值。我可以将它分配给选项value = ...标签 likehere第一个选项vaue工作正常,但我想每次传递diff名称,所以我怎么能传递该字符串变量。

<script type="text/javascript">
    var test="117960298357503_22120.mp4";
</script>

<OPTION value="J:\Users\ADITYARAJ SINGH\Downloads\Video\117960298357503_22120.mp4">My Video File </OPTION>
<OPTION value="J:\Users\ADITYARAJ SINGH\Downloads\Video\('+ test +')">My Video1 File </OPTION>

1 个答案:

答案 0 :(得分:0)

给你的选项一个id,然后用jquery获取它并设置它的值:

HTML标记:

<OPTION value="J:\Users\ADITYARAJ SINGH\Downloads\Video\117960298357503_22120.mp4">My Video File </OPTION>
<OPTION value="" id="myoption">My Video1 File </OPTION>

和脚本:

$(function () {
    var test = "117960298357503_22120.mp4";
    $('#myoption').attr('value', 'J:\Users\ADITYARAJ SINGH\Downloads\Video\' + test);
});