能否把PHP代码放进一个JS文件里面调用来执行?解决问题追加200分。
比如一段PHP代码是$elements['displayheader']=<<<eot<divid="wrapper"><divid="innerWrapper"><di...
比如一段PHP代码是
$elements['displayheader']=<<<eot
<div id="wrapper">
<div id="innerWrapper">
<div id="header">
<div id="innerHeader">
<div id="blogLogo">
</div>
<div class="blog-header">
<div class="blog-search">
<form method="post" action="visit.php">
<input name="job" type="hidden" value="search"/>
<input name="searchmethod" type="hidden" value="2"/>
<input name="keyword" value="Search..." onfocus="if (value =='Search...'){value =''}" onblur="if (value ==''){value='Search...'}" type="text" id="search-text"/>
<input class="button" src="{$template['images']}/search.gif" name="searchsubmit" value="Go" id="search-img" type="image"/>
</form>
</div>
</div>
<div id="menu">
<ul>
{section_head_components}
</ul>
</div>
</div>
</div>
eot;
我把它转换为JS,并保存为a.js
document.writeln("$elements[\'displayheader\']=<<<eot");
document.writeln("<div id=\"wrapper\">");
document.writeln(" <div id=\"innerWrapper\">");
document.writeln(" <div id=\"header\">");
document.writeln(" <div id=\"innerHeader\">");
document.writeln(" <div id=\"blogLogo\">");
document.writeln(" <\/div>");
document.writeln(" <div class=\"blog-header\">");
document.writeln(" <div class=\"blog-search\">");
document.writeln(" <form method=\"post\" action=\"visit.php\">");
document.writeln(" <input name=\"job\" type=\"hidden\" value=\"search\"\/>");
document.writeln(" <input name=\"searchmethod\" type=\"hidden\" value=\"2\"\/>");
document.writeln(" <input name=\"keyword\" value=\"Search...\" onfocus=\"if (value ==\'Search...\'){value =\'\'}\" onblur=\"if (value ==\'\'){value=\'Search...\'}\" type=\"text\" id=\"search-text\"\/>");
document.writeln(" <input class=\"button\" src=\"{$template[\'images\']}\/search.gif\" name=\"searchsubmit\" value=\"Go\" id=\"search-img\" type=\"image\"\/>");
document.writeln(" <\/form>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <div id=\"menu\">");
document.writeln(" <ul>");
document.writeln(" {section_head_components}");
document.writeln(" <\/ul>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln("eot;")
然后用<script language="javascript" src="/a.js"></script>,发现网站打开空白,是我哪个步骤错误,还是在JS文件中是无法执行PHP代码 ,请指教。
有什么办法把一段带有那些是“函数”的代码吧?放到另一个文件里面,再调用执行过来,因为在网站中,有一段代码执行会有大量的代码的,我只是不想显示在源代码中。 展开
$elements['displayheader']=<<<eot
<div id="wrapper">
<div id="innerWrapper">
<div id="header">
<div id="innerHeader">
<div id="blogLogo">
</div>
<div class="blog-header">
<div class="blog-search">
<form method="post" action="visit.php">
<input name="job" type="hidden" value="search"/>
<input name="searchmethod" type="hidden" value="2"/>
<input name="keyword" value="Search..." onfocus="if (value =='Search...'){value =''}" onblur="if (value ==''){value='Search...'}" type="text" id="search-text"/>
<input class="button" src="{$template['images']}/search.gif" name="searchsubmit" value="Go" id="search-img" type="image"/>
</form>
</div>
</div>
<div id="menu">
<ul>
{section_head_components}
</ul>
</div>
</div>
</div>
eot;
我把它转换为JS,并保存为a.js
document.writeln("$elements[\'displayheader\']=<<<eot");
document.writeln("<div id=\"wrapper\">");
document.writeln(" <div id=\"innerWrapper\">");
document.writeln(" <div id=\"header\">");
document.writeln(" <div id=\"innerHeader\">");
document.writeln(" <div id=\"blogLogo\">");
document.writeln(" <\/div>");
document.writeln(" <div class=\"blog-header\">");
document.writeln(" <div class=\"blog-search\">");
document.writeln(" <form method=\"post\" action=\"visit.php\">");
document.writeln(" <input name=\"job\" type=\"hidden\" value=\"search\"\/>");
document.writeln(" <input name=\"searchmethod\" type=\"hidden\" value=\"2\"\/>");
document.writeln(" <input name=\"keyword\" value=\"Search...\" onfocus=\"if (value ==\'Search...\'){value =\'\'}\" onblur=\"if (value ==\'\'){value=\'Search...\'}\" type=\"text\" id=\"search-text\"\/>");
document.writeln(" <input class=\"button\" src=\"{$template[\'images\']}\/search.gif\" name=\"searchsubmit\" value=\"Go\" id=\"search-img\" type=\"image\"\/>");
document.writeln(" <\/form>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <div id=\"menu\">");
document.writeln(" <ul>");
document.writeln(" {section_head_components}");
document.writeln(" <\/ul>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln("eot;")
然后用<script language="javascript" src="/a.js"></script>,发现网站打开空白,是我哪个步骤错误,还是在JS文件中是无法执行PHP代码 ,请指教。
有什么办法把一段带有那些是“函数”的代码吧?放到另一个文件里面,再调用执行过来,因为在网站中,有一段代码执行会有大量的代码的,我只是不想显示在源代码中。 展开
2个回答
展开全部
一、你那些DIV代码不显示在源代码里面几乎是不可能的,因为这些东西只有浏览器才执行。放在JS里面只是不让别人一眼就看到而已,完全不让见是不可能的。
二、你想用<script language="javascript" src="/a.js"></script>调用的a.js代码,只需要下面这样即可:
document.writeln("<div id=\"wrapper\">");
document.writeln(" <div id=\"innerWrapper\">");
document.writeln(" <div id=\"header\">");
document.writeln(" <div id=\"innerHeader\">");
document.writeln(" <div id=\"blogLogo\">");
document.writeln(" <\/div>");
document.writeln(" <div class=\"blog-header\">");
document.writeln(" <div class=\"blog-search\">");
document.writeln(" <form method=\"post\" action=\"visit.php\">");
document.writeln(" <input name=\"job\" type=\"hidden\" value=\"search\"\/>");
document.writeln(" <input name=\"searchmethod\" type=\"hidden\" value=\"2\"\/>");
document.writeln(" <input name=\"keyword\" value=\"Search...\" onfocus=\"if (value ==\'Search...\'){value =\'\'}\" onblur=\"if (value ==\'\'){value=\'Search...\'}\" type=\"text\" id=\"search-text\"\/>");
document.writeln(" <input class=\"button\" src=\"{$template[\'images\']}\/search.gif\" name=\"searchsubmit\" value=\"Go\" id=\"search-img\" type=\"image\"\/>");
document.writeln(" <\/form>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <div id=\"menu\">");
document.writeln(" <ul>");
document.writeln(" {section_head_components}");
document.writeln(" <\/ul>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
不涉及PHP的内容。
二、你想用<script language="javascript" src="/a.js"></script>调用的a.js代码,只需要下面这样即可:
document.writeln("<div id=\"wrapper\">");
document.writeln(" <div id=\"innerWrapper\">");
document.writeln(" <div id=\"header\">");
document.writeln(" <div id=\"innerHeader\">");
document.writeln(" <div id=\"blogLogo\">");
document.writeln(" <\/div>");
document.writeln(" <div class=\"blog-header\">");
document.writeln(" <div class=\"blog-search\">");
document.writeln(" <form method=\"post\" action=\"visit.php\">");
document.writeln(" <input name=\"job\" type=\"hidden\" value=\"search\"\/>");
document.writeln(" <input name=\"searchmethod\" type=\"hidden\" value=\"2\"\/>");
document.writeln(" <input name=\"keyword\" value=\"Search...\" onfocus=\"if (value ==\'Search...\'){value =\'\'}\" onblur=\"if (value ==\'\'){value=\'Search...\'}\" type=\"text\" id=\"search-text\"\/>");
document.writeln(" <input class=\"button\" src=\"{$template[\'images\']}\/search.gif\" name=\"searchsubmit\" value=\"Go\" id=\"search-img\" type=\"image\"\/>");
document.writeln(" <\/form>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <div id=\"menu\">");
document.writeln(" <ul>");
document.writeln(" {section_head_components}");
document.writeln(" <\/ul>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
document.writeln(" <\/div>");
不涉及PHP的内容。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询