0
텍스트가 들어있는 페이지에 URL이있는 코드를 복사하여 붙여 넣습니다. exmaple에 대한jQuery를 사용하여 텍스트 영역 내부에있는 URL의 하위 도메인 변경
:
<textarea><a href="http://anything.domain.com/x/5">something</a></textarea>
<textarea><a href="http://anything.domain.com/x/3">something</a></textarea>
나는 또한 페이지의 모든 텍스트 영역 내부의 하위 도메인을 변경의 의도와 하위 도메인 옵션의 무리와 함께 드롭 다운을 보유하고 있습니다.
예컨대
<select class="changeLinks">
<option value="www">www.domain.com</option>
<option value="somethingelse">somethingelse.domain.com</option>
</select>
방법이 텍스트 영역을 통과하는 단지 하위 도메인의 텍스트를 업데이트? 나는이 기능을 테스트하지 않았습니다
var text = $("textarea").each(function(){
$(this).text($(this).text().replace(/<a href="http:\/\/\w+\.domain\.com(.*?)">(.*?)<\/a>/gi, "<a href=\"http://"+subdomain+".domain.com"+$1+"\">"+$2+"</a>"));
});
을하지만, 그것을 작동합니다 :
$('.changeLinks').change(function(){
var subdomain = $(this).val();
// *blank* some sort of find and replace function which replaces whatever is after the http:// and before the first decimal with the var subdomain
});
정규식이 어떻게 작동하는지 잘 모르겠습니다. 바꾸기 함수의 두 번째 부분에서는 따옴표를 취소하지만 첫 번째 부분은 취소하지 않습니다./gi는 무엇을합니까? 미안 해요 마리우스 내가 LOL을 디버깅하기 전에 그것을 이해해야합니다. 그것을 위해 고마워요,하지만 내게는 효과가있는 것처럼 보입니다.하지만 왜 그렇게되지는 모르겠습니다. – willdanceforfun
http://www.javascriptkit.com/javatutors/re.shtml – Marius