Modernizr负载问题

时间:2011-04-09 20:46:07

标签: javascript html5 placeholder modernizr

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

我的问题是因为我使用模板结构(MVC)作为我的代码库,我不确定如何让“if()”脚本适用于我的特定页面,因为它必须在风景。我把我的现代化脚本移到了我的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>

1 个答案:

答案 0 :(得分:0)

您是否收到任何Javascript错误?

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