【发布时间】:2020-04-21 20:36:40
【问题描述】:
我正在尝试将属性添加到从 ahref html 标记中获取的链接,请任何人指导我,我在这做错了什么?
链接将从 ahref 标签中获取,语言和货币从下拉列表中获取,然后最终链接将是 "link+"index.php?lang="+lang+"¤cy="+currency;"
$(document).ready(function(){
var saveclass = null;
function onChangeHandler() {
const lang = document.querySelector('#lang').value;
const currency = document.querySelector('#currency').value;
var link=document.querySelector('#theButton')..getAttribute('href');
var strLink = link+"index.php?lang="+lang+"¤cy="+currency;
document.querySelector('#theButton').setAttribute('href', strLink);
}
onChangeHandler();
document.querySelector('#lang').addEventListener('change', onChangeHandler);
document.querySelector('#currency').addEventListener('change', onChangeHandler);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="price_billing.js"></script>
</head>
<body>
<select name="" id="lang">
<option value="English">English</option>
<option value="French">French</option>
<option value="Spanish">Spanish</option>
</select>
<select name="" id="currency">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="MXN">MXN</option>
</select>
<a href="https://alpha.com" id="theButton">Click</a>
<select name="" id="lang">
<option value="English">English</option>
<option value="French">French</option>
<option value="Spanish">Spanish</option>
</select>
<select name="" id="currency">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="MXN">MXN</option>
</select>
<a href="https://alpha.com" id="theButton">Click</a>
</body>
</html>
【问题讨论】:
标签: javascript java php