![](/img/trans.png)
[英]Getting the Value of an innerHTML of a select tag with JQuery
[英]How to change the innerHTML value specifically from the select tag in jquery?
我正在编写代码以允许用户在该域上创建自定义。 正如您在下面的示例中所看到的,用户可以选择example.com并通过从下面的选择标签中选择将其更改为任何example(n).com域。
我试图实现的是当我选择example1.com或example3.com 时, http://将更改为https://
例子:
当我从选择列表中选择 example1.com 时,输出将是
https://example1.com
https://example3.com
但如果我选择example2.com / example4.com ,它将保持原样。
HTTP:// example2.com
HTTP:// example4.com
我正在尝试在 jquery 中实现它。 任何帮助和建议将不胜感激。
function changeText(url) { document.getElementById('mydiv').innerHTML = url; }
<div>http://<span id='mydiv'>example0.com</span></div> <select onchange='changeText(this.value)'> <option>example1.com</option> <option>example2.com</option> <option>example3.com</option> <option>example4.com</option> </select>
看看这个片段。
function changeText(urlPostFixNumber) { var protocol; var url; var domain = '://example' + urlPostFixNumber + '.com'; switch(urlPostFixNumber) { case "1": case "3": protocol = 'https'; break; default: protocol = 'http'; } url = protocol + domain; document.getElementById('mydiv').textContent = url; }
<p id="mydiv">http://example0.com</p> <select onchange="changeText(this.value)"> <option value="0" selected>example0.com</option> <option value="1">example1.com</option> <option value="2">example2.com</option> <option value="3">example3.com</option> <option value="4">example4.com</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.