문자열을 숫자로 변환하고 하나 더하기
ID에서 얻은 값을 숫자로 바꾸고 여기에 1을 더한 다음 dosomething()
사용할 함수에 새 값을 전달하고 싶습니다 . 내가 이것을 시도하고 값이 1이면 2가 아닌 11을 반환합니다.
$('.load_more').live("click",function() { // When user clicks
var newcurrentpageTemp = $(this).attr("id") + 1;// Get id from the hyperlink
alert(parseInt(newcurrentpageTemp));
dosomething();
});
정확하고 ID가 적절한 숫자 (다른 텍스트없이)라고 가정하면 ID를 구문 분석 한 다음 여기에 추가해야합니다.
var currentPage = parseInt($(this).attr('id'), 10);
++currentPage;
doSomething(currentPage);
플립 플롭을 조금 시도해 보셨습니까?
var newcurrentpageTemp = parseInt($(this).attr("id"));
newcurrentpageTemp++;
alert(newcurrentpageTemp));
parseInt에 전달한 후 1을 더해야한다고 생각합니다.
$('.load_more').live("click",function() { //When user clicks
var newcurrentpageTemp = parseInt($(this).attr("id")) + 1;
alert(newcurrentpageTemp);
dosomething();
});
$('.load_more').live("click",function() { //When user clicks
var newcurrentpageTemp = parseInt($(this).attr("id")) + 1
dosomething(newcurrentpageTemp );
});
Id를 문자열로 구문 분석 한 다음 추가합니다.
예 :
$('.load_more').live("click",function() { //When user clicks
var newcurrentpageTemp = parseInt($(this).attr("id")) + 1;//Get the id from the hyperlink
alert(newcurrentpageTemp);
dosomething();
});
1을 추가하기 전에 ID를 구문 분석해야합니다.
$('.load_more').live("click",function() { //When user clicks
var newcurrentpageTemp = parseInt($(this).attr("id"));
newcurrentpageTemp ++;
dosomething(newcurrentpageTemp );
});
나는 다음과 같이 다음 페이지로 이동하기 위해 비슷한 상황에서 작동합니다.
$("#page_next").click(function () {
$("#pageNumber").val(parseInt($("#pageNumber").val()) + 1);
submitForm(this);
return false;
});
다음과 같이 원하는 것을 얻기 위해 대괄호를 추가 할 수 있어야합니다.
var newcurrentpageTemp = (parseInt($(this).attr("id"))) + 1;//Get the id from the hyperlink
여기서 가장 간단한 해결책은
var newcurrentpageTemp = $(this).attr("id") + 1;//Get the id from the hyperlink
에:
var newcurrentpageTemp = (($(this).attr("id")) * 1) + 1;//Get the id from the hyperlink
The parseInt solution is the best way to go as it is clear what is happening.
For completeness it is worth mentioning that this can also be done with the + operator
$('.load_more').live("click",function() { //When user clicks
var newcurrentpageTemp = +$(this).attr("id") + 1; //Get the id from the hyperlink
alert(newcurrentpageTemp);
dosomething();
});
var sVal = '234';
var iNum = parseInt(sVal); //Output will be 234.
http://www.jquerybyexample.net/2013/02/jquery-convert-string-to-integer.html
a nice way from http://try.jquery.com/levels/4/challenges/16 :
adding a + before the string without using parseInt and parseFloat and radix and errors i faced for missing radix parameter
sample
var number= +$('#inputForm').val();
var first_value = '2';
// convert this string value into int
parseInt(first_value);
Simple and best solution is like this. take a string in one variable and then convert it using parseInt() method like below.
var stringValue = '921795';
var numValue = parseInt(stringValue);
parseInt() method will return the number like this 921795. after this, you can add any number to your value.
http://www.phpcodify.com/convert-string-to-integer-using-jquery-parseint/
참고URL : https://stackoverflow.com/questions/7674475/convert-string-to-number-and-add-one
'development' 카테고리의 다른 글
express.js-한 줄의 여러 경로에 대한 단일 라우팅 처리기 (0) | 2020.09.02 |
---|---|
변수가 존재하는지 여부를 모르는 경우 정의되지 않은 변수와 비교하는 방법은 무엇입니까? (0) | 2020.09.02 |
Play 프레임 워크 2.0에서 MySQL 데이터베이스를 사용하는 데 필요한 단계 (0) | 2020.09.02 |
StatusStrip에서 컨트롤을 오른쪽 정렬하려면 어떻게합니까? (0) | 2020.09.02 |
Java에서 정수를 문자열로 캐스팅 할 수없는 이유는 무엇입니까? (0) | 2020.09.02 |