잘못된 용어를 말하면 자바 스크립트에서 4 시간 미만의 경험이 있습니다. 내가 뭘 하려는지 자바 스크립트에있는 미리 정의 된 DIV의 끝에 변수를 추가하는 것입니다.자바 스크립트 함수 내에서 DIV에 변수 삽입
jQuery(function ($) {
var OSX = {
container: null,
init: function() {
$("[id^=osx").click(function (e) {
e.preventDefault();
$("[id^=osx-modal-content]").modal({OPTIONS});
그리고이 : 나는 현재이 가지고있는 자바 스크립트 함수에서
<input type="button" name="osx<?php echo $x;?>" value="View" class="osx<?php echo $x;?>" id="osx<?php $x;?>"/>
<div id="osx-modal-content<?php echo $x;?>" style="display:none">
: 여기
<?php
$n = rand(10e16, 10e20);
$x = base_convert($n, 10, 36);
?>
가 사용 변수 :
여기 예를 들어
이 변수 :
open: function (d) {
var self = this;
self.container = d.container[0];
d.overlay.fadeIn('slow', function() {
$("[id^=osx-modal-content]" + $x, self.container).show();
분명히 시작은 최상의 해결책이 아닙니다. onclick 이벤트가 발생하면 osx-modal-content로 시작하는 페이지의 모든 DIVS가 활성화됩니다. 그래서 그것은 잘 조절되어야합니다.
어떻게 자바 스크립트에 변수를 추가 할 수 있도록 그 같은 .... 예를 들면의 말을 할 것
$("osx" + $x).click(function (e) {
$("#osx-modal-content" + $x).modal({OPTIONS});
$("#osx-modal-content" + $x, self.container).show();
$ X 12345 그래서 자바 스크립트 .....
로 읽을 것 =
$("osx12345") etc..........
$("#osx-modal-content12345") etc.......
$("#osx-modal-content12345", self.container etc.......
음에 OSX 변수를 사용할 수 있습니다, 예. 당신이 쓴 것이 효과가 있습니다. 작동하지 않는 것이 있습니까? – idrumgood
코드가 게시 된 코드와 정확히 일치합니까? 마지막 단락에서 두 번째로 클릭 이벤트가 jquery 선택기에 #이 없습니다. – mattytommo
죄송합니다.이 정보가 충분하다고 생각합니다. 자바 스크립트는 꼬리말에 코드가있는 인라인이 아니며 페이지가로드 될 때 잡아 당겼습니다. Chrome에서 검사 할 때이 오류가 발생합니다. Uncaught ReferenceError : $ x이 정의되지 않았습니다. 전체 코드는 http://stackoverflow.com/questions/10126931/bizarre-simplemodal-osx-actions-in-foreach-loop –