【发布时间】:2018-02-14 18:18:38
【问题描述】:
我的问题是。我想在发送之前更改所需的表单字段。当从没有 php number_format 的后端加载时,它们将 periots 显示为十进制分隔符,这是我不想要的,但该字段需要这个。 magento 类验证字段,我不想自己改回数字或让客户自己做。在(模糊)或单击时进行更改(更改)是没有问题的。
但我希望在提交表单时更改该字段。这是html:
<form>
<input id="price" value="
<?php if (isset ( $productPrice )) {
echo number_format($productPrice, '2', ',', '.');
} ?>" class="validate-zero-or-greater input-text validation-passed"
type="text">
</form>
<button class="button" id="actionbutton"
onclick="function(),checkTextarea()" type="submit" title="<?php echo $this-
>__('Save Product') ?>">
</button>
和第一行有我的问题的 jQuery 脚本:
$("#price").(function(){
event.preventDefault();
if (jQuery('#price').val().includes(',')) {
var varwithComma = jQuery('#price').val();
varwithoutComma = varwithComma.replace(",",".");
jQuery('#price').val(varwithoutComma);
} else {
console.log('No Comma');
};
我猜,由于 on change 事件,第一行的代码运行良好。
jQuery('form').on('change', '#price', function(event){
【问题讨论】:
标签: jquery onclick magento-1.9