gpt4 book ai didi

javascript - 从所选选项中获取 href 值并更改按钮的 href

转载 作者:行者123 更新时间:2023-11-30 16:03:40 26 4
gpt4 key购买 nike

我想获取所选选项的 href 值,以便我现在可以转到使用按钮选择的链接。

这是我的代码

<div class="modal fade" id="soa">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Choose the name of student</h4>
</div>

<div class="modal-body">
<div class="col-md-12">
<div class="form-group">
<label class="control-label"><span
class="text-danger"></span> Name of Student</label>
<select name="childNames" class="form-control input-lg" id="childNames" data-size="5">
<option value="" selected disabled></option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice">John Dela Cruz</option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice1">Josh Dela Cruz </option>
<option value="${pageContext.request.contextPath}/app/billsandpayments/invoice2">Jane Dela Cruz</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<a href=''><button type="button" class="btn btn-info">View</button></a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

最佳答案

添加一个id到=>

<a id="link" href=''><button type="button" class="btn btn-info">View</button></a>

这应该有效:

$(document).ready(function() {

$("#childNames").on('change', function () {

var ref = document.getElementById("childNames").value;
alert(ref);
$('#link').attr('href', ref);

});

});

jsfiddle example

关于javascript - 从所选选项中获取 href 值并更改按钮的 href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37338932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com