用JS插入值

我有以下 html:


<div class="col-md-1 col-lg-1 text-center">

<input name="flash_price" type="hidden" id="test" value="">

<input name="from" type="hidden" value="">

<input name="to" type="hidden" value="">

<button type="button" id="my" class="btn btn-secondary" data-container="body" data-toggle="popover" data-placement="top" data-content="<div class='form-group row'><label class='col-sm-2 control-label'>Price<span class='text-danger'>*</span></label><div class='col-md-8 col-lg-10'><input name='special_price' type='text' class='form-control'></div></div><p>This product shall be displayed on the Flash sale. Creating flash sales increases the chance of product being sold.</p><div class='form-group row'> <label class='col-sm-2 control-label'>From<span class='text-danger'>*</span></label> <div class='col-md-8 col-lg-10'> <input name='starting_date' type='datetime-local' class='form-control' required value></div></div><div class='form-group row'><label class='col-sm-2 control-label'>To<span class='text-danger'>*</span></label> <div class='col-md-8 col-lg-10'> <input name='ending_date' type='datetime-local' class='form-control' required value></div></div><a id='optBtn' class='btn btn-primary input-group-addon'>OK</a>" title="" data-html="true" data-original-title="Flash Sales Price" aria-describedby="popover917523"><i class="fa fa-edit"></i></button>

</div>

我正在尝试用 js 来增加价值,如下所示:


$(this).parent('col-md-1').find('input[name=flash_price]').attr('value', 'test value);

但当我尝试$(this).parent('col-md-1').find('input[name=flash_price]').attr('id');这样做时,它说未定义。我在那里做错了什么?


守候你守候我
浏览 84回答 1
1回答

杨__羊羊

把你的js改成这样$(this).parent('.col-md-1').find('input[name ="flash_price"]').val('test value');
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript