Modernizr 负载问题

发布于 2024-10-31 15:11:55 字数 2868 浏览 4 评论 0原文

我已将 Modernizr 安装到我的代码中,以在 firefox 3.6 中启用 html5 占位符支持

我的问题是,因为我使用模板结构 (MVC) 作为我的代码库,所以我不确定如何让“if()”脚本工作对于我的特定页面,因为它必须在视图中调用。我已将 Modernizr 脚本移至我的 haeder ->在我的页脚中

我的表单:

 <?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$saleName = array('id' => 'name', 'name' => 'name', 'placeholder' => 'Name*');
$saleLocation = array('id' => 'location', 'name' => 'location', 'placeholder' => 'Location*');
$saleBedrooms = array('id' => 'bedrooms','name' => 'bedrooms', 'placeholder' => 'Number of Bedrooms*');
$saleBathrooms = array('id' => 'bathrooms','name' => 'bathrooms', 'placeholder' => 'Number of Bathrooms*');
$saleCondition = array('id' => 'condition','name' => 'condition', 'placeholder' => 'Condition*');
$saleImage = array('id' => 'userfile', 'name'=> 'userfile', 'placeholder' => 'File Location*');
$saleDescription = array('id' => 'description','name' => 'description', 'placeholder' => 'Sale Description*');
$salePrice = array('id' => 'price','name' => 'price', 'placeholder' => 'Price*');
?>

<section id = "validation"><?php echo validation_errors();?></section>
<?php 
echo form_open_multipart('admin/addsale/', $formAddSale);
echo form_fieldset(); 
echo form_input($saleName);
echo form_input($saleLocation);
echo form_input($saleBedrooms);
echo form_input($saleBathrooms);
echo form_input($saleCondition);
echo form_input($salePrice);
echo form_upload($saleImage);
echo form_textarea($saleDescription);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?>

在撰写此问题时,我使用以下代码创建了一个“misc.js”文档:

    // if placeholder isn't supported:
if (!Modernizr.input.placeholder){
  // use a input hint script
    setInputHint(document.getElementById('name'),'Name*');
    setInputHint(document.getElementById('location'),'Location*');
    setInputHint(document.getElementById('bedrooms'),'Number of Bedrooms*');
    setInputHint(document.getElementById('bathrooms'),'Number of Bathrooms*');
    setInputHint(document.getElementById('condition'),'Condition*');
    setInputHint(document.getElementById('price'),'Price*');
    setInputHint(document.getElementById('description'),'Sale Description*');
    setInputHint(document.getElementById('userfile'),'File Location*');
   }

我已像平常一样将上述文档包含在“模板”的页脚中

<!-- jQuery Files --> 
<script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> 
<script type="text/javascript" src="http://www.domain.co.nz/includes/js/placeholder.js"></script> 
<script type="text/javascript" src="http://www.domain.co.nz/includes/js/misc.js">    </script>

I have installed Modernizr into my code to enable html5 placeholder support in firefox 3.6

My issue is that because I am using a template structure (M.V.C) as my code base, I am unsure how I can get the "if()" script to work for my particular page as it would have to be called in the view. I have moved my modernizr script into my haeder -> was in my footer

My Form:

 <?php
//Setting form attributes
$formAddSale = array('id' => 'addSale', 'name' => 'addSale');
$saleName = array('id' => 'name', 'name' => 'name', 'placeholder' => 'Name*');
$saleLocation = array('id' => 'location', 'name' => 'location', 'placeholder' => 'Location*');
$saleBedrooms = array('id' => 'bedrooms','name' => 'bedrooms', 'placeholder' => 'Number of Bedrooms*');
$saleBathrooms = array('id' => 'bathrooms','name' => 'bathrooms', 'placeholder' => 'Number of Bathrooms*');
$saleCondition = array('id' => 'condition','name' => 'condition', 'placeholder' => 'Condition*');
$saleImage = array('id' => 'userfile', 'name'=> 'userfile', 'placeholder' => 'File Location*');
$saleDescription = array('id' => 'description','name' => 'description', 'placeholder' => 'Sale Description*');
$salePrice = array('id' => 'price','name' => 'price', 'placeholder' => 'Price*');
?>

<section id = "validation"><?php echo validation_errors();?></section>
<?php 
echo form_open_multipart('admin/addsale/', $formAddSale);
echo form_fieldset(); 
echo form_input($saleName);
echo form_input($saleLocation);
echo form_input($saleBedrooms);
echo form_input($saleBathrooms);
echo form_input($saleCondition);
echo form_input($salePrice);
echo form_upload($saleImage);
echo form_textarea($saleDescription);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?>

At the time of writing this question I have created a 'misc.js' document with the following code:

    // if placeholder isn't supported:
if (!Modernizr.input.placeholder){
  // use a input hint script
    setInputHint(document.getElementById('name'),'Name*');
    setInputHint(document.getElementById('location'),'Location*');
    setInputHint(document.getElementById('bedrooms'),'Number of Bedrooms*');
    setInputHint(document.getElementById('bathrooms'),'Number of Bathrooms*');
    setInputHint(document.getElementById('condition'),'Condition*');
    setInputHint(document.getElementById('price'),'Price*');
    setInputHint(document.getElementById('description'),'Sale Description*');
    setInputHint(document.getElementById('userfile'),'File Location*');
   }

I have included the above document as you normally would in the footer of my "template"

<!-- jQuery Files --> 
<script type="text/javascript"    src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> 
<script type="text/javascript" src="http://www.domain.co.nz/includes/js/placeholder.js"></script> 
<script type="text/javascript" src="http://www.domain.co.nz/includes/js/misc.js">    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2024-11-07 15:11:55

您遇到任何 Javascript 错误吗?

因为您使用的是 JS 库 (jQuery),所以您可以将 'document.getElementById' 替换为 '$',从​​而节省大量编码。

Are you getting any Javascript errors ?

Because you are using a JS library ( jQuery ) you can replace 'document.getElementById' with '$' so save a lot of coding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文