javascript - 如何将选项的值解析为输入值
问题描述
很抱歉,这个问题有点像这个问题的重复:Parse value of option into html attribute但我不知道如何更改我的问题的答案。我正在尝试做同样的事情,只是我试图不将其解析为“数据销售产品”,而我试图将其放入“价值”中。
这是应将值插入到的按钮的代码:
<form class="flex-c-m stext-101 cl0 size-101 bg1 bor1 hov-btn1 p-lr-15 trans-04" name="PrePage" method = "post" action = "https://scotest.authorize.net/payment/CatalogPayment.aspx"> <input class="js-addcart-detail" type = "hidden" name = "LinkId" value ="" /> <input type = "image" src ="//testcontent.authorize.net/images/buy-now-gold.gif" /> </form>
其余的与其他问题完全相同
我尝试更改此代码:
<script type="text/javascript">
function getComboA(selectObject) {
const button = document.querySelector('button.js-addcart-detail');
button.dataset.sellyProduct = selectObject.value;
console.log(button);
}
</script>
对此:
<script type="text/javascript">
function getComboA(selectObject) {
const button = document.querySelector('form.js-addcart-detail');
form.value = selectObject.value;
console.log(button);
}
</script>
开发者控制台中的错误消息:
ReferenceError: form is not defined
但这不起作用。
解决方案
If I don't misunderstood your question, then this is what you want to achieve. You basically want to set the selected option's value
on a hidden
input fields value
.
function getComboA(selectObject) {
const input = document.querySelector('input.js-addcart-detail');
input.value = selectObject.value;
console.log(input);
}
<select class="js-select2" name="time" id="comboA" onchange="getComboA(this)">
<option value="">Choose an option</option>
<option value="3cffe13b">Size S</option>
<option value="M">Size M</option>
<option value="L">Size L</option>
<option value="XL">Size XL</option>
</select>
<input class="js-addcart-detail" type="hidden" name="LinkId" value="" />
<button class="flex-c-m stext-101 cl0 size-101 bg1 bor1 hov-btn1 p-lr-15 trans-04 js-addcart-detail">Add to cart</button>
推荐阅读
- excel - 在“_”字符处截断所有工作表的名称
- python - Tkinter GUI 不显示 windows 屏幕
- android - Flutter - 获取实际的 Android 设备名称
- python - 在 sklearn 中读取 arff 文件
- php - PHP 致命错误:未捕获错误:使用 Laravel 5.8 和 PHP 7.4 调用未定义函数 Whoops\Exception\xdebug_is_enabled()
- haskell - SublimeHaskell 在运行检查时没有看到额外的deps
- reactjs - 使用 React 延迟加载模块?
- python - 我是否可以同时使用“f”来格式化字符串和“r”来查找文件?
- react-native - 无法从 navigation.navigate 读取参数
- javascript - 遍历 response.data 未按预期工作