开发者

Unable to .append(); without eliminating all the spaces in the code

$('#form_holder').append('<div id="spec_id_'+count+'"><div class="avail_container">

<input class="avail_fields" type="checkbox" checked="checked" name="special'+count+'" /><span class="avail_field_label">Special Date</span></div>
<div class="avail_container"><div class="avail_time_container"><span class="field_label">Time</span>
    <select name="special'+count+'_time_from_1">

    <?php
        for ($t = 0; $t<24; $t++){
        ?>
        <option value="<?php echo $t; ?>"><?php echo $t; ?></option>

        <?php
        }

        ?>
    </select>:
    <select name="special'+count+'_time_from_2">
            <?php
        for ($t = 0; $t<60; $t+=15){
        ?>
        <option value="<?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?>"><?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?></option>

        <?php
        }

        ?>
    </select>

    <span class="field_label">to</span>
    <select name="special'+count+'_time_to_1">
        <?php
        for ($t = 0; $t开发者_JAVA技巧<24; $t++){
        ?>
        <option value="<?php echo $t; ?>"><?php echo $t; ?></option>

        <?php
        }

        ?>
    </select>:
    <select name="special'+count+'_time_to_2">
                    <?php
        for ($t = 0; $t<60; $t+=15){
        ?>
        <option value="<?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?>"><?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?></option>

        <?php
        }

        ?>
    </select>

    </div>
</div>
</div>');

I'm assuming javascript or jquery does not like breaks like I have here, because all my javascript code does not work.

What would be an alternative to eliminating all the spaces, which would make viewing the code difficult?


Try this not checked

var varVal1=<?php
        for ($t = 0; $t<24; $t++){
        ?>
            <option value="<?php echo $t; ?>"><?php echo $t; ?></option>
        <?php
        }
        ?>;
var varVal2=<?php
        for ($t = 0; $t<60; $t+=15){
        ?>
            <option value="<?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?>"><?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?></option>
        <?php
        }
        ?>
var varVal3=<?php
        for ($t = 0; $t<24; $t++){
        ?>
            <option value="<?php echo $t; ?>"><?php echo $t; ?></option>
        <?php
        }
        ?>
var varVal4=<?php
        for ($t = 0; $t<60; $t+=15){
        ?>
            <option value="<?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?>"><?php if($t == 0){ echo $t . '' . $t; }else{ echo $t; } ?></option>
        <?php
        }
        ?>
$('#form_holder').append('<div id="spec_id_'+count+'">'+
    '<div class="avail_container">'+
    '<input class="avail_fields" type="checkbox" checked="checked" name="special'+count+'" />'+
    '<span class="avail_field_label">Special Date</span>'+
    '</div>'+
    '<div class="avail_container">'+
    '<div class="avail_time_container">'+
    '<span class="field_label">Time</span>'+
    '<select name="special'+count+'_time_from_1">'+varVal1+
    '</select>:'+
    '<select name="special'+count+'_time_from_2">'+varVal2+
    '</select>'+
    '<span class="field_label">to</span>'+
    '<select name="special'+count+'_time_to_1">'+varVal3+
    '</select>:'+
    '<select name="special'+count+'_time_to_2">'+varVal4+             
    '</select>'+
    '</div>'+
'</div>'+
'</div>');

with regards

Wazzy


You could escape the line breaks.

var str = 'this is a string\
           on multiple lines\
           with the line breaks escaped.'

or concatenate the string.

var str = 'this is a string' +
          'on multiple lines' +
          'with the line breaks escaped.'


ok, first, to allow a javascript string to span multiple lines end every line with a backslash

etc...

var string = 'This is a javascript\
              string that spans\
              multiple lines';

Second, PHP code cannot be rendered in javascript so your code will be simply displayed and not processed like you are wanting it to be.

I would recommend using ajax to go out and grab the html you want to be appended so the php is processed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜