gpt4 book ai didi

javascript - 如何在javascript中将值返回到控制台?

转载 作者:行者123 更新时间:2023-12-02 18:29:35 25 4
gpt4 key购买 nike

我正在尝试编写一些 JavaScript,当用户单击相应的文本时,它将返回 toasty.png 和 bready.png 的值。我可以返回“Toast”和“bread”,但不能返回其他文本。有什么建议吗?

<script>
$(document).on('vclick', '.changePageButton', function() {
console.log(this.text);
//console.log(value within the image)
});
</script>

<a class="changePageButton" value="Toast" data-transition="slide">
<input type = "hidden" name = "image" value = "toasty.png">
<input type = "hidden" name = "video" value = "video1.mpg">
test
</a>

<a class="changePageButton" value="bread" data-transition="slide">
<input type = "hidden" name = "image" value = "bready.png">
<input type = "hidden" name = "video" value = "video2.mpg">
test
</a>

最佳答案

// Also did you mean "click"?
$(document).on('click', '.changePageButton', function () {
var inputs = {};

console.log(this.text);

$(this).children('input').each(function (v) {
inputs[$(this).prop('name')] = $(this).val();
});

console.log(inputs);
console.log(inputs.image);
console.log(inputs.video);
});

关于javascript - 如何在javascript中将值返回到控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961553/

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