jq动态改变路径_jQuery - 如何动态更改值?(jQuery - How dynamically change the value?)

jQuery - 如何动态更改值?(jQuery - How dynamically change the value?)

我有我的HTML代码:

我想jQuery检测用户选择了哪个项目,然后根据公式设置值:如果用户选择值为“1”的radiobutton,则id =“crc”的输入值应为:“20120109 | 1”而不是“20120109 | 0”。 换句话说 - 在签名之前保留所有数字“|” 并仅更改此符号“|”后面的值。 我怎样才能做到这一点? 也许从id =“crc”取值,删除最后一个号码并添加新号码? 或者以另一种方式?

$('.hidd').click(function () {

});

I have in my html code:

I want to jQuery detect which item was selected by user and then set the value according to the formula: if radiobutton with value "1" is selected by user then input value of id="crc" should be: "20120109|1" instead of "20120109|0". So in other words - keep all numbers before sign "|" and change only value behind this sign "|". How can I do that? Maybe take value from id="crc", delete last number and add new number? Or maybe in another way?

$('.hidd').click(function () {

});

原文:https://stackoverflow.com/questions/8820204

更新时间:2020-01-26 10:04

最满意答案

尝试这个:

$('.hidd').click(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] + "|" + $(this).val());

});

或者涵盖选择选项的所有可能方法:

$('.hidd').change(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] + "|" + $(this).val());

});

Try this:

$('.hidd').click(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] + "|" + $(this).val());

});

Or to cover all possible methods of selecting an option:

$('.hidd').change(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] + "|" + $(this).val());

});

2012-01-11

相关问答

jQuery等同于你的vanilla Javascript代码将是: var id = $("#id_Value")[0];

id.points[4].y=233;

请注意,使用jQuery操作SVG时可能会遇到许多问题。 jQuery只能用于HTML,而不是SVG。 有许多jQuery函数不适用于SVG元素。 The jQuery equivalent of your vanilla Javascript code would be: var id = $("#id_Value")[0];

i

...

请使用此代码 $(document).ready(function() {

$("span").each(function(){

if (parseInt($(this).text()) > 0){

$(this).removeClass("cart-summary__count");

$(this).addClass("cart-summary__count_full");

}

});

});

请参阅此Fiddle 编辑 根据您的编辑,使

...

问题是你的输入是一个复选框,所以你需要'检查'它:) $('#test').on('click', function(){

$('#flip1').attr('checked','checked');

$('#flip1').flipswitch( "refresh" )

});

小提琴 The problem is that your input is a checkbox, so you need to 'Check' it :) $('#test').on('click

...

1.您可以使用input或keyup方法。 2. .val()会给你一个字符串值,所以将它与0.2比较,在parseFloat()的帮助下将其转换为float 如下: - 例1: - jQuery('input').on('input', function () {

var myInput = jQuery(this);

if (parseFloat(myInput.val()) < 0.2 ) {

jQuery('.alert').css('display'

...

我希望它会对你有所帮助: var temp;

var nums = [];

$(document).ready(function () {

$('.pass').each(function(i, obj) {

do {

temp = Math.floor(Math.random() * 9) + 1;

$(this).attr("placeholder", temp);

} while (nums.index

...

这是因为你传递给css方法一个包含property属性的对象。 在这种情况下,最好将两个参数传递给css方法: function changeProperty(mine , property , value){

$(mine).css(property, value);

}

但是,如果您想传递一个对象,则可以动态构建它: function changeProperty(mine , property , value){

var obj = {};

obj[property

...

假设所有链接都有一个superspeciallink类链接类,这应该工作: $('a.superspeciallink').bind('click', function(){

var querystring = this.search; // The search property of links gives you the querystring section of their href

var originalhref = this.href;

$('a.supe

...

尝试这个: $('.hidd').click(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] + "|" + $(this).val());

});

或者涵盖选择选项的所有可能方法: $('.hidd').change(function () {

var crc = $("#crc").val().split("|");

$("#crc").val(crc[0] +

...

如果你想每5秒更改一次,你需要使用setInterval() : var loop = 1;

setInterval(function() {

var imgNumber = loop % 5; // assuming there are 5 images.

$.backstretch("site.com/images/home" + imgNumber + ".jpg");

loop++;

}, 5000);

UPDATE 阅读完文档后,该功能已经嵌入到插件中: htt

...

多种方法来解决它。 要么不使用type="submit"要么不通过代码提交。 表格实际上是默认提交的。 你可以这样做 Save

function submitForm()

{

$('#formId').attr('action', 'saveQuery').submit();

}

或者在提交之前更改操作.

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值