如何在javascript中向控制台返回值
How to return value to console in javascript?
我正在尝试编写一些javascript,当用户单击相应的文本时,它将返回toasty.png和bready.png的值。我可以返回"Toast"answers"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);
});
尝试这个
$(document).on('vclick','.changePageButton', function() {
console.log($(this).find("input[type='hidden']").val());
// if you want according to hidden field name
console.log($(this).find("input[name='image']").val());
});
我希望它能帮助
可用于获取元素的Form标签
<script>
$(document).on('vclick','.changePageButton', function() {
var frm = document.getElementById('ID');
// jQuery frm = $("#ID")
console.log(this.text);
console.log(frm.image.value[0]);
console.log(frm.image.value[1]);
// or you can use loop FOR, WHILE etc
});
</script>
<form id="ID">
<a class = "changePageButton" value = "Toast" data-transition="slide">
<input type = "hidden" name = "image" value = "toasty.png">
test
</a>
<a class = "changePageButton" value = "bread" data-transition="slide">
<input type = "hidden" name = "image" value = "bready.png">
test
</a>
</form>
相关文章:
- 控制台返回var不是't定义,但它是
- Javascript返回值只在循环中返回一次
- XMLHttpRequest未返回值-状态202
- 根据是否解析了 Promise 从函数返回值
- Angular,函数在(模型)工厂中返回值
- AngularJS错误:提供程序必须从$get工厂方法返回值
- 如何从客户端的数组中获取用户输入和返回值
- Javascript中带有返回值的嵌套函数
- 为变量分配多个nodejs导出返回值时出现问题
- 通过回调从onreadystatechange返回值
- 从Ajax函数返回值
- JavaScript生成器中收益率返回值的解析
- HTML如何根据javascript函数的返回值限制文本输入
- 返回值+new Date()与Date.now()是否不同
- 使用在函数外部声明的变量的 Javascript 返回值 + undefined
- 从控制台获取值.log并在输入字段中显示/打印/返回
- 我无法让它作为 JavaScript 函数工作(我在控制台时得到我想要的返回值.log但我不能将其作为函数调用)
- 如何在javascript中向控制台返回值
- Javascript函数可以写入控制台,但不能返回值
- 用于“返回值”的控制台符号