有人能帮忙吗?
我想将显示在id=result的div中的结果分配给一个变量,在选择了一个分配了价格的下拉框列表后,我可以使用该变量将其放入mysql数据库字段。
这就是我现在所拥有的。
<script>
$("#country").on("change", function(){
var selected = $(this).val();
$("#results").html("Estimated Postage: " + selected);
})
</script>
<div id='result'>Abracadabra</div>
<script>
var a = $('#result').attr('id'); // to extract the id of this div
var b = $('#result').html(); // to extract the html content of this div
var c = $('#result').text(); // to extract only the text from this div
console.log('a = ', a);
console.log('b = ', b);
console.log('c = ', c);
</script>
如果div是在页面完全加载后动态生成的,请在选择器中使用静态父级,如下所示:
$('body #result').html();