Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

javascript - 从更改时选择中获取选定的值/文本(Get selected value/text from Select on change)

<select onchange="test()" id="select_id">
    <option value="0">-Select-</option>
    <option value="1">Communication</option>
</select>

I need to get the value of the selected option in javascript: does anyone know how to get the selected value or text, please tell how to write a function for it.(我需要在javascript中获取所选选项的值:有没有人知道如何获取所选值或文本,请告诉我们如何为它编写函数。)

I have assigned onchange() function to select so what do i do after that?(我已经分配了onchange()函数来选择那么我之后做了什么?)   ask by Siva translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use either JavaScript or jQuery for this.(为此使用JavaScript或jQuery。)

Using JavaScript(使用JavaScript) <script> function val() { d = document.getElementById("select_id").value; alert(d); } </script> <select onchange="val()" id="select_id"> Using jQuery(使用jQuery) $('#select_id').change(function(){ alert($(this).val()); })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...