i have following part of code: <input id="add" class="add" data-amount="150" data-monthly="25" type="checkbox" name="accessory[]" value="Accessory Name"/>
wondering if there any way to post all data in "value", "data-amount" and "data-monthly" together to another script?
我有以下部分代码:想知道是否有方法将"value"、"data-amount"和"data-monthly"的所有数据一起发布到另一个脚本中?
4 个解决方案
#1
0
To get all those values in the checkbox, you can concatenate them together separated by some delimiter and then split the value when processing the form.
要在复选框中获取所有这些值,可以将它们连接在一起,由一些分隔符分隔,然后在处理表单时分割值。
<input type="checkbox" name="accessory[]" value="Accessory Name*150*25"/>
This is not an elegant solution. It does what you ask, but you should strongly consider Sohnee's answer as a better method of doing what you want to do.
这不是一个优雅的解决方案。它会按照你的要求去做,但是你应该把Sohnee的答案作为一个更好的方法来做你想做的事情。
#2
4
If you are writing the value of those attributes onto the page server side, you are better off working off of a key and retrieving the values again server side based on the key. The HTML could be altered resulting in non-trustworthy data being send back.
如果您将这些属性的值写入到页面服务器端,那么您最好使用一个密钥,并根据密钥重新检索值。HTML可能会被修改,导致不可信任的数据被发送回来。
For example...
例如……
<input id="add" class="add" data-amount="150" data-monthly="25" type="checkbox" name="accessory[]" value="1"/>
Where 1
is the id of the data that contains the amount and monthly data.
其中1是包含数量和每月数据的数据的id。
#3
0
Data attributes are not submitted with form data.
数据属性不是通过表单数据提交的。
#4
0
No there is not, however you can put all the attributes you need in hidden fields which are passed with form.
没有,但是你可以把你需要的所有属性都放在表单中。
#1
0
To get all those values in the checkbox, you can concatenate them together separated by some delimiter and then split the value when processing the form.
要在复选框中获取所有这些值,可以将它们连接在一起,由一些分隔符分隔,然后在处理表单时分割值。
<input type="checkbox" name="accessory[]" value="Accessory Name*150*25"/>
This is not an elegant solution. It does what you ask, but you should strongly consider Sohnee's answer as a better method of doing what you want to do.
这不是一个优雅的解决方案。它会按照你的要求去做,但是你应该把Sohnee的答案作为一个更好的方法来做你想做的事情。
#2
4
If you are writing the value of those attributes onto the page server side, you are better off working off of a key and retrieving the values again server side based on the key. The HTML could be altered resulting in non-trustworthy data being send back.
如果您将这些属性的值写入到页面服务器端,那么您最好使用一个密钥,并根据密钥重新检索值。HTML可能会被修改,导致不可信任的数据被发送回来。
For example...
例如……
<input id="add" class="add" data-amount="150" data-monthly="25" type="checkbox" name="accessory[]" value="1"/>
Where 1
is the id of the data that contains the amount and monthly data.
其中1是包含数量和每月数据的数据的id。
#3
0
Data attributes are not submitted with form data.
数据属性不是通过表单数据提交的。
#4
0
No there is not, however you can put all the attributes you need in hidden fields which are passed with form.
没有,但是你可以把你需要的所有属性都放在表单中。