Javascript | onClick函数没有在.php页面上执行

时间:2016-02-17 12:36:25

标签: javascript php jquery html

我创建了一个非常基本的js来调用依赖于用户输入到文本字段的图像(即 - 'brick1'调用image brick1.jpg)。这将适用于普通的html页面,但是当我尝试添加到.php页面时,onClick不会触发。由于我是PHP新手,所以非常感谢任何帮助。

以下是我正在使用的内容:

<script type="text/javascript">
	var brickPath = "http://www.legoexample.com.au" + "/brickdata/";

	function dothisnow(name){
		var picId = document.images["imageId"];	
		picId.src = brickPath + name + "_T.jpg";
	}
</script>

<form name="myForm">
	<p style="text-align: center;">	Enter Lego Part #<br>
	<input type=text	name="picid"	size="25">
	<br><br>
	<input type=button value="Click Here to See Your Photo"	name="clicker" onClick="dothisnow(document.forms['myForm'].elements['picid'].value);">
	<br>
	<img id="imageId"	onerror="alert('Could not find the image.');">
</form>

<script type="text/javascript">
	dothisnow('brick1');
<script>

这是PHP:

    <?php

if($new_auction_step == 2)
{

    $img_nr = get_option("ad_theme_pic_nr");
    $catid  = $_SESSION['posted_thing_cat'];
    $wii = get_option('ad_uploaded_image_width');

    if(empty($img_nr)) $img_nr = 5;

    global $current_user;
    get_currentuserinfo();
    $cid = $current_user->ID;


    if($uploaders == "html") $enc = 'enctype="multipart/form-data"';

    ?>
    <!-- ###########################  -->
    <?php

        if($uploaders == "jquery"):

    ?>

    <ul class="post-new">
    <li>
                            <h2><?php echo __('Images', 'AuctionTheme'); ?>:</h2>
                            <p>

    <div id="mcont">
    <form id="fileupload" action="<?php bloginfo('siteurl'); ?>/?uploady_thing=1&pid=<?php echo $pid; ?>" method="POST" enctype="multipart/form-data">
    <input type="hidden" name="pid" value="<?php echo $pid; ?>">
    <input type="hidden" name="cid" value="<?php echo $cid; ?>">

        <!-- Redirect browsers with JavaScript disabled to the origin page -->
        <noscript><input type="hidden" name="redirect" value="http://blueimp.github.com/jQuery-File-Upload/"></noscript>
        <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
        <div class="row fileupload-buttonbar">
            <div class="span7">
                <!-- The fileinput-button span is used to style the file input field as button -->
                <span class="btn btn-success fileinput-button">
                    <i class="icon-plus icon-white"></i>
                    <span><?php _e('Add files...','AuctionTheme') ?></span>
                    <input type="file" name="files[]" multiple>
                </span>

                <button type="reset" class="btn btn-warning cancel">
                    <i class="icon-ban-circle icon-white"></i>
                    <span><?php _e('Cancel upload','AuctionTheme') ?></span>
                </button>
                <button type="button" class="btn btn-danger delete">
                    <i class="icon-trash icon-white"></i>
                    <span><?php _e('Delete','AuctionTheme') ?></span>
                </button>
                <input type="checkbox" class="toggle">
            </div>
            <!-- The global progress information -->
            <div class="span5 fileupload-progress fade">
                <!-- The global progress bar -->
                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                    <div class="bar" style="width:0%;"></div>
                </div>
                <!-- The extended global progress information -->
                <div class="progress-extended">&nbsp;</div>
            </div>
        </div>
        <!-- The loading indicator is shown during file processing -->
        <div class="fileupload-loading"></div>
        <br>
        <!-- The table listing the files available for upload/download -->
        <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
    </form>

<!-- modal-gallery is the modal dialog used for the image gallery -->
<div id="modal-gallery" class="modal modal-gallery hide fade" data-filter=":odd" tabindex="-1">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">&times;</a>
        <h3 class="modal-title"></h3>
    </div>
    <div class="modal-body"><div class="modal-image"></div></div>
    <div class="modal-footer">
        <a class="btn modal-download" target="_blank">
            <i class="icon-download"></i>
            <span>Download</span>
        </a>
        <a class="btn btn-success modal-play modal-slideshow" data-slideshow="5000">
            <i class="icon-play icon-white"></i>
            <span>Slideshow</span>
        </a>
        <a class="btn btn-info modal-prev">
            <i class="icon-arrow-left icon-white"></i>
            <span>Previous</span>
        </a>
        <a class="btn btn-primary modal-next">
            <span>Next</span>
            <i class="icon-arrow-right icon-white"></i>
        </a>
    </div>
</div>


<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td class="preview"><span class="fade"></span></td>
        <td class="name"><span>{%=file.name%}</span></td>
        <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
        {% if (file.error) { %}
            <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
        {% } else if (o.files.valid && !i) { %}
            <td>
                <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
            </td>
            <td class="start">{% if (!o.options.autoUpload) { %}
                <button class="btn btn-primary">
                    <i class="icon-upload icon-white"></i>
                    <span><?php _e('Start','AuctionTheme') ?></span>
                </button>
            {% } %}</td>
        {% } else { %}
            <td colspan="2"></td>
        {% } %}
        <td class="cancel">{% if (!i) { %}
            <button class="btn btn-warning">
                <i class="icon-ban-circle icon-white"></i>
                <span><?php _e('Cancel','AuctionTheme') ?></span>
            </button>
        {% } %}</td>
    </tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        {% if (file.error) { %}
            <td></td>
            <td class="name"><span>{%=file.name%}</span></td>
            <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
            <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
        {% } else { %}
            <td class="preview">{% if (file.thumbnail_url) { %}
                <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
            {% } %}</td>
            <td class="name">
                <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
            </td>
            <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
            <td colspan="2"></td>
        {% } %}
        <td class="delete">
            <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                <i class="icon-trash icon-white"></i>
                <span><?php _e('Delete','AuctionTheme') ?></span>
            </button>
            <input type="checkbox" name="delete" value="1">
        </td>
    </tr>
{% } %}
</script>

</div>


                            </p>
                            </li>

    </ul>    


    <?php endif; //endif jquery uploads ?>


    <!-- ########################## -->

    <form method="post" <?php echo $enc; ?>  action="<?php echo AuctionTheme_post_new_with_pid_stuff_thg($pid, $new_auction_step);?>" > 
      <ul class="post-new">

      <?php
        if($uploaders == "html"):
      ?>

 <li>
                            <h2><?php echo __('Images', 'AuctionTheme'); ?>:</h2>
                            <p>
          <?php

                $args = array(
                'order'          => 'ASC',
                'orderby'        => 'post_date',
                'post_type'      => 'attachment',
                'post_parent'    => $pid,
                'post_mime_type' => 'image',
                'numberposts'    => -1,
                ); $i = 0;

                $attachments = get_posts($args);

                $default_nr = get_option('AuctionTheme_nr_max_of_images');
                if(empty($default_nr)) $default_nr = 5;

                $actual_nr = count($attachments);
                $dis = $default_nr - $actual_nr;

                for($i=1;$i<=$dis;$i++):
                ?>                   

                    <input type="file" class="do_input file_inpt" name="file_<?php echo $i; ?>" />

                <?php   endfor; ?>

                          </p>
                            </li>

                           <li>

                            <div id="thumbnails" style="overflow:hidden;">

                                          <script type="text/javascript">

    function delete_this3(id)
    {
         jQuery.ajax({
                        method: 'get',
                        url : '<?php echo get_bloginfo('siteurl');?>/?_ad_delete_pid='+id,
                        dataType : 'text',
                        success: function (text) {   jQuery('#image_ss'+id).remove(); window.location.reload();  }
                     });
          //alert("a");

    }

</script>


    <?php



    if($pid > 0)
    if ($attachments) {
        foreach ($attachments as $attachment) {
        $url = wp_get_attachment_url($attachment->ID);

            echo '<div class="div_div2"  id="image_ss'.$attachment->ID.'"><img width="70" class="image_class" height="70" src="' .
            AuctionTheme_wp_get_attachment_image($attachment->ID, array(70, 70)). '" />
            <a href="javascript: void(0)" onclick="delete_this3(\''.$attachment->ID.'\')"><img border="0" src="'.get_template_directory_uri().'/images/delete_icon.png" /></a>
            </div>';

    }
    }


    ?>

    </div>

                           </li>


<?php endif; //image uploaders html ?>

1 个答案:

答案 0 :(得分:0)

如果它在html中工作它也应该在php中工作,你能展示php吗?问题可能在于语法或js集成。我会尽力帮助你。