English 中文(简体)
jquery 如何通过寻找全面强化的国际发展法来选择下降的选择
原标题:jquery How to select option in drop down by finding expected full string ID

我试图从下降中挑选一个数字数值,这里是代码线。

rowid = LogGridId(gridId, row);
$(`#${rowid}`).find(`select option[value^= IDnum ]`).prop("selected", true);

But I want showing the first value (1) before first semicolon in option value when ID=1 is selected from example <option value="1;A;0.0000;False;True">ID10 (9.00%)</option> <option value="15;T;0.0000;True;True">Jon (10.00%)</option> <option value="12;Y;0.0000;True;True">Bam (0.00%)</option>

现在我的问题是,在我选择ID=1时,它总是以1为起点显示最低地位,因此,在我选择ID=1时,ID=12将显示这一点,但预期结果显示ID=1。

Do anyone know how to solve it? by just modify this line of code, not include option value above. $(#${rowid}).find(select option[value^= IDnum ]).prop("selected", true);

我如何从选择价值中适当提取数字价值,然后将价值分成头半殖民地

问题回答

使用分立,由半殖民地分立,头一次。

 const displayValue = (e) => 
    document.getElementById( selectedValueDisplay ).innerHTML =
     Selected Value:   + e.target.value.split( ; )[0];
  
<Select onchange="displayValue(event)">
<option value="1;A;0.0000;False;True">ID10 (9.00%)</option>
<option value="15;T;0.0000;True;True">Jon (10.00%)</option>
<option value="12;Y;0.0000;True;True">Bam (0.00%)</option>
<option value="2;T;0.0000;False;True">Pole (0.00%)</option>
</Select>

<p id="selectedValueDisplay">Selected Value: </p>

你们可以 gr取价值,把价值分开, first首象样:

$( select ).on( change , function(e) {
  $( #selected-value ).text( Selected:   + $(this).val().split( ; ).shift());
}).trigger( change );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<select>
  <option value="1;A;0.0000;False;True">ID10 (9.00%)</option>
  <option value="15;T;0.0000;True;True">Jon (10.00%)</option>
  <option value="12;Y;0.0000;True;True">Bam (0.00%)</option>
  <option value="2;T;0.0000;False;True">Pole (0.00%)</option>
</select>

<p id="selected-value">Selected:</p>

这里是一片杂草:

(function($) {
  $.fn.tokenizedValue = function(delimiter =  ; ) {
    return this.val().split(delimiter);
  };
  $.fn.valueAt = function(index = 0, delimiter =  ; ) {
    return this.tokenizedValue(delimiter)[index];
  };
  $.fn.firstValue = function(index = 0, delimiter =  ; ) {
    return this.tokenizedValue(delimiter).shift();
  };
  $.fn.lastValue = function(index = 0, delimiter =  ; ) {
    return this.tokenizedValue(delimiter).pop();
  };
})(jQuery);

$( select ).on( change , function(e) {
  $( #selected-value ).text( Selected:   + $(this).firstValue());
}).trigger( change );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<select>
  <option value="1;A;0.0000;False;True">ID10 (9.00%)</option>
  <option value="15;T;0.0000;True;True">Jon (10.00%)</option>
  <option value="12;Y;0.0000;True;True">Bam (0.00%)</option>
  <option value="2;T;0.0000;False;True">Pole (0.00%)</option>
</select>

<p id="selected-value">Selected:</p>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签