【发布时间】:2017-07-27 23:54:33
【问题描述】:
我正在尝试更改我的 href 值,但它似乎根本没有改变。 jQuery 和 javascript 方法我都试过了,都不管用。
<a type="button" class="view_me btn btn-primary" href="#">View Full</a>
$(document).on("click", ".click_row", function (e) {
e.preventDefault();
var _self = $(this);
userId = _self.data('id');
var newLink = '/users/view/' + userId //I'd like to eventually use this as new href link
$(".view_me").prop("href", "www.google.com"); // Tried testing with a simple webpage
// document.getElementById('view_test').href = "www.google.com"; // Tried this as well, doesn't work
console.log(newLink)
});
任何建议都会有所帮助。我正在使用 jQuery 3.2.1
【问题讨论】:
-
www.google.com不是有效的 URL。改用http://www.google.com -
view_test和click_row在哪里 -
<a type="button" class="view_me btn btn-primary" href="#">View Full</a>没有 IDview_test。 -
添加minimal reproducible example html 以重现问题
-
你需要将
id="view_test"添加到你的锚元素
标签: javascript jquery href ejs