向javascript输入框插入元素
To insert elements into the javascript input box
我是学生JavaScript。我想把strong标签中的checkValue值放入输入框,但是不知道怎么写JavaScript才能进入输入框。我需要找到 cart_table 个 div 吗?还是我应该找一个强标签?
<script>
$().ready(function() {
$("#optionSelect").change(function() {
var checkValue = $("#optionSelect").val();
var checkText = $("#optionSelect option:selected").text();
var product = $("#productname").text();
var price = parseInt($("#price").text());
var test = parseInt($(this).find(':selected').data('price'));
var hapgae = price + test
if (checkValue != "no") {
var whtml =
" <div class=\"cart_table\">\n" +
" <hr style='width: 300px; margin-bottom: 30px;'>" +
" <p style='font-size: 17px;'>" + product + "</p>" +
" <p style='font-size: 13px; margin-top: -10px; class=\"check\" margin-bottom: 20px;'>" + checkText + "</p>" +
" <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
" <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +
strong tags和input tags参考这部分
" <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
" <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +
首先我建议你使用反引号
var html = `
<div>
<span>Some HTML here ${some_var}</span>
</div>
`;
这样可以节省您的时间和精力,然后您可以随心所欲地插入变量
同时查看此线程
Creating multiline strings in JavaScript
我是学生JavaScript。我想把strong标签中的checkValue值放入输入框,但是不知道怎么写JavaScript才能进入输入框。我需要找到 cart_table 个 div 吗?还是我应该找一个强标签?
<script>
$().ready(function() {
$("#optionSelect").change(function() {
var checkValue = $("#optionSelect").val();
var checkText = $("#optionSelect option:selected").text();
var product = $("#productname").text();
var price = parseInt($("#price").text());
var test = parseInt($(this).find(':selected').data('price'));
var hapgae = price + test
if (checkValue != "no") {
var whtml =
" <div class=\"cart_table\">\n" +
" <hr style='width: 300px; margin-bottom: 30px;'>" +
" <p style='font-size: 17px;'>" + product + "</p>" +
" <p style='font-size: 13px; margin-top: -10px; class=\"check\" margin-bottom: 20px;'>" + checkText + "</p>" +
" <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
" <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +
strong tags和input tags参考这部分
" <strong class=\"value_code2\">" + checkValue + "</strong>\n" +
" <input name=\"value_code\" id=\"value_code\" class=\"value_code\">" +
首先我建议你使用反引号
var html = `
<div>
<span>Some HTML here ${some_var}</span>
</div>
`;
这样可以节省您的时间和精力,然后您可以随心所欲地插入变量
同时查看此线程
Creating multiline strings in JavaScript