我使用以下代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select name="cars" id="dynamic_select">
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Borrowing-Power-Calculator.aspx?ID=MFAA">Borrowing Power Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Loan-Repayment-Calculator.aspx?ID=MFAA">Loan Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Lump-Sum-Repayment-Calculator.aspx?ID=MFAA">Lump Sum Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Extra_Repayment_Calculator.aspx?ID=MFAA">Extra Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Budget-Planner.aspx?ID=MFAA">Budget Planner</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Loan-Comparison-Calculator.aspx?ID=MFAA">Loan Comparison Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/How-Long-to-Repay-Calculator.aspx?ID=MFAA">How Long to Repay Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Split-Loan-Calculator.aspx?ID=MFAA">Split Loan Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Property-Selling-Cost-Calculator.aspx?ID=MFAA">Property Selling Cost Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Property-Buying-Cost-Calculator.aspx?ID=MFAA">Property Buying Cost Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Saving-Calculator.aspx?ID=MFAA">Saving Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Term-Deposit-Calculator.aspx?ID=MFAA">Term Deposit Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Stamp-Duty-Calculator.aspx?ID=MFAA">Stamp Duty Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Credit-Card-Calculator.aspx?ID=MFAA">Credit Card Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Income-Tax-Calculator.aspx?ID=MFAA">Income Tax Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Reverse-Mortgage-Calculator.aspx?ID=MFAA">Reverse Mortgage Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Leasing-Calculator.aspx?ID=MFAA">Leasing Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Home-Loan-Offset-Calculator.aspx?ID=MFAA">Home Loan Offset Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Honeymoon-Loan-Calculator.aspx?ID=MFAA">Honeymoon Loan Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Comparison-Rate-Calculator.aspx?ID=MFAA">Comparison Rate Calculator</option>
</select>
<script>
$(function() {
// bind change event to select
$('#dynamic_select').on('change', function() {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
目前,表单更改会将浏览器发送到URL:
http://www.visionabacus.com/default.aspx?go=
我不明白需要改变什么。
你能帮帮忙吗?
答案 0 :(得分:6)
你的代码很好。链接坏了。如果您手动输入它们,您将看到服务器端的应用程序正在进行重定向。
答案 1 :(得分:0)
试试这个......
<script>
$(function(){
// bind change event to select
$('#dynamic_select').on('change', function () {
var url = $(this).find(":selected").val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
答案 2 :(得分:0)
我把它绑起来并且工作得很好,所以它不是代码。
<select name="cars" id="dynamic_select">
<option value="http://www.google.com">Borrowing Power Calculator</option>
</select>
<script>
$(function(){
// bind change event to select
$('#dynamic_select').on('change', function () {
var url = $(this).val(); // get selected value
console.log(url);
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
答案 3 :(得分:0)
试试这个,你的一个也行得正常
<script>
$(function() {
// bind change event to select
$(document).on('change','#dynamic_select', function() {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location.href = url; // redirect
}
return false;
});
});
</script>
答案 4 :(得分:0)
链接在您的选项中被破坏。从下面的示例中,使用第二个选项。来检查它。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$('#dynamic_select').on('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = url; // redirect
}
return false;
});
});
</script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<select name="cars" id="dynamic_select">
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Borrowing-Power-Calculator.aspx?ID=MFAA">Borrowing Power Calculator</option>
<option value="http://stackoverflow.com/questions/35261589/html-form-select-with-jquery-not-working">Your Question</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Loan-Repayment-Calculator.aspx?ID=MFAA">Loan Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Lump-Sum-Repayment-Calculator.aspx?ID=MFAA">Lump Sum Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Extra_Repayment_Calculator.aspx?ID=MFAA">Extra Repayment Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Budget-Planner.aspx?ID=MFAA">Budget Planner</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Loan-Comparison-Calculator.aspx?ID=MFAA">Loan Comparison Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/How-Long-to-Repay-Calculator.aspx?ID=MFAA">How Long to Repay Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Split-Loan-Calculator.aspx?ID=MFAA">Split Loan Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Property-Selling-Cost-Calculator.aspx?ID=MFAA">Property Selling Cost Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Property-Buying-Cost-Calculator.aspx?ID=MFAA">Property Buying Cost Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Saving-Calculator.aspx?ID=MFAA">Saving Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Term-Deposit-Calculator.aspx?ID=MFAA">Term Deposit Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Stamp-Duty-Calculator.aspx?ID=MFAA">Stamp Duty Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Credit-Card-Calculator.aspx?ID=MFAA">Credit Card Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Income-Tax-Calculator.aspx?ID=MFAA">Income Tax Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Reverse-Mortgage-Calculator.aspx?ID=MFAA">Reverse Mortgage Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Leasing-Calculator.aspx?ID=MFAA">Leasing Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Home-Loan-Offset-Calculator.aspx?ID=MFAA">Home Loan Offset Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Honeymoon-Loan-Calculator.aspx?ID=MFAA">Honeymoon Loan Calculator</option>
<option value="http://www.visionabacus.com/Australia/1/SuiteA100/640/Comparison-Rate-Calculator.aspx?ID=MFAA">Comparison Rate Calculator</option>
</select>
</body>
</html>