반응형
IE8과 JQuery의 trim ()
나는 다음과 같이 trim ()을 사용하고 있습니다.
if($('#group_field').val().trim()!=''){
group_field
텍스트 유형의 입력 요소는 어디에 있습니까 ? 이것은 Firefox에서 작동하지만 IE8에서 시도하면 다음 오류가 발생합니다.
Message: Object doesn't support this property or method
trim ()을 제거하면 IE8에서 잘 작동합니다. trim () 사용하는 방식이 맞다고 생각 했습니까?
도움을 주셔서 감사합니다.
대신 이것을 시도하십시오.
if($.trim($('#group_field').val()) != ''){
더 많은 정보:
다음과 같이을 사용해야합니다 $.trim
.
if($.trim($('#group_field').val()) !='') {
// ...
}
내가 아는 한 Javascript String에는 트림 메소드가 없습니다. 기능 트림을 사용하려면
<script>
$.trim(string);
</script>
또 다른 옵션은 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();
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' 카테고리의 다른 글
Sublime Text 3에서 현재 파일 경로를 (쉽게) 얻는 방법 (0) | 2020.08.14 |
---|---|
Python이 64 비트 애플리케이션으로 실행 중인지 어떻게 감지합니까? (0) | 2020.08.14 |
기본 액세스 수정자는 무엇입니까? (0) | 2020.08.14 |
UI 테스트 실패-요소 나 하위 요소 모두 secureTextField에 키보드 포커스가 없습니다. (0) | 2020.08.14 |
JavaScript를 사용하여 데이터 속성 설정 (0) | 2020.08.14 |