반응형
IE8 및 JQuery의 트림()
트림()을 다음과 같이 사용하고 있습니다.
if($('#group_field').val().trim()!=''){
어디에group_field
형식 텍스트의 입력 요소입니다.Firefox에서 작동하지만 IE8에서 시도하면 다음 오류가 발생합니다.
Message: Object doesn't support this property or method
트림()을 제거하면 IE8에서 잘 작동합니다.트림()을 사용하는 방법이 정확하다고 생각했습니다.
모든 도움에 감사드립니다.
대신 사용해 보십시오.
if($.trim($('#group_field').val()) != ''){
추가 정보:
다음과 같이 사용해야 합니다.
if($.trim($('#group_field').val()) !='') {
// ...
}
다른 옵션은 메소드를 직접 정의하는 것입니다.String
누락된 경우:
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
//Your implementation here. Might be worth looking at perf comparison at
//http://blog.stevenlevithan.com/archives/faster-trim-javascript
//
//The most common one is perhaps this:
return this.replace(/^\s+|\s+$/g, '');
}
}
그리고나서trim
브라우저에 관계없이 작동합니다.
var result = " trim me ".trim();
Javascript String은 메서드 트림이 없는 것으로 알고 있습니다.기능 트림을 사용하려면 다음을 사용합니다.
<script>
$.trim(string);
</script>
jQuery를 사용하여 유형 텍스트로 입력을 전역적으로 트리밍하려면:
/**
* Trim the site input[type=text] fields globally by removing any whitespace from the
* beginning and end of a string on input .blur()
*/
$('input[type=text]').blur(function(){
$(this).val($.trim($(this).val()));
});
언급URL : https://stackoverflow.com/questions/3439316/ie8-and-jquerys-trim
반응형
'programing' 카테고리의 다른 글
dataType jsonp와 JSON의 차이 (0) | 2023.08.17 |
---|---|
옵션 Bool 값 확인 (0) | 2023.08.17 |
현재 페이지 가져오기 (0) | 2023.08.17 |
테이블 잠금 없이 거대한 MariaDB 프로덕션 데이터베이스에 인덱스 생성 (0) | 2023.08.17 |
PL/SQL 개발자의 그리드 출력에서 numwidth를 설정하는 방법은 무엇입니까? (0) | 2023.08.17 |