gpt4 book ai didi

jquery - 获取动态添加按钮的值

转载 作者:行者123 更新时间:2023-12-01 00:13:35 25 4
gpt4 key购买 nike

我正在构建一个简单的问卷应用程序。

我当前的函数检索每个问题的选项并将它们附加为按钮。我想编写另一个函数preparefornextquestion来提醒所选按钮的值。当前似乎没有获得点击的值。 :(

$('#option_one').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion()' value='" + arr[0].option_one + "'>" + arr[0].option_one + "</button>").trigger('create');

$('#option_two').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion()' value='" + arr[0].option_two + "'>" + arr[0].option_two + "</button>").trigger('create');

$('#option_three').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion()' value='" + arr[0].option_three + "'>" + arr[0].option_three + "</button>").trigger('create');

function preparefornextquestion(){
$(document).ready(function() {
$('.option').click(function() {
alert($(this).attr("value"));
});
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="option_one"></div>
<div id="option_two"></div>
<div id="option_three"></div>

最佳答案

$('#option_one').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion(this)' value='" + arr[0].option_one + "'>" + arr[0].option_one + "</button>").trigger('create');

$('#option_two').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion(this)' value='" + arr[0].option_two + "'>" + arr[0].option_two + "</button>").trigger('create');

$('#option_three').append("<button data-role='button' class='option' data-inline='true' data-mini='true' data-theme='b' onclick='preparefornextquestion(this)' value='" + arr[0].option_three + "'>" + arr[0].option_three + "</button>").trigger('create');


function preparefornextquestion(val){
alert($(val).attr('value'))
}

关于jquery - 获取动态添加按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40560682/

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